/*
 * @Author: JYJ 
 * @Date: 2020-07-13 10:52:28 
 * @Desc: 相机类,  注意egret坐标原点在左上角
 */
namespace gf {
    export class Camera extends BaseClass {

        private layers: Array<egret.DisplayObjectContainer>;
        private stage: egret.Stage;
        private posX: number = 0;
        private posY: number = 0;
        public constructor() {
            super();
            this.layers = new Array<egret.DisplayObjectContainer>();
        }
        public static getInstance(): Camera {
            return super.getInstance();
        }
        public init(stage: egret.Stage) {
            this.stage = stage;
        }
        public addLayers(...layer: egret.DisplayObjectContainer[]) {
            for (let l of layer) {
                this.layers.push(l);
                if (!this.stage.contains(l)) {
                    this.stage.addChild(l);
                }
            }
        }
        public setPosition(posX: number, posY: number): void {
            let deltaX = this.posX - posX;
            let deltaY = this.posY - posY;
            for (let l of this.layers) {
                l.x = l.x + deltaX;
                l.y = l.y + deltaY;
                if (l instanceof (UILayer)) {
                    //ui先不移动
                } else if (l instanceof (SpriteLayer)) {
                    //相机移动其实就是场景往反方向移动delta
                    // l.x = l.x + deltaX;
                    // l.y = l.y + deltaY;
                }
            }
            this.posX = posX;
            this.posY = posY;
        }
    }
}